package top.hzy520.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import top.hzy520.feign.PostPointsMessageClient;
import top.hzy520.order.dao.MessageEventPublishMapper;
import top.hzy520.order.entity.MessageEventPublish;

/**
 * @Author: HouZeYu
 * @Description: 定时扫描信息发送表 (如果发现新插入的信息 则调用远程服务 投递消息)
 * @Date: Created in 20:45 2018/7/20
 */
public class PostPointsMessageSimpleJob implements SimpleJob {
    @Autowired
    private MessageEventPublishMapper messageEventPublishMapper;

    @Autowired
    private PostPointsMessageClient postPointsMessageClient;

    @Override
     public void execute(ShardingContext shardingContext) {
        System.out.println("定时扫描发送信息执行");
      //1.查询信息发送表
        MessageEventPublish messageEventPublish= messageEventPublishMapper.selectByStatus();
        //2. 调用远程发送消息接口定时发送
        if (messageEventPublish!=null) {
            postPointsMessageClient.postPointsMessage(messageEventPublish.getPayload());
        }
    }
}
